package com.example.stockservice.controller;

import com.example.stockservice.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/stock")
public class StockController {

    @Autowired
    private StockService stockService;

    // 扣减库存
    @PostMapping("/deduct")
    public boolean deductStock(
            @RequestParam String productId,
            @RequestParam int quantity
    ) {
        return stockService.deduct(productId, quantity);
    }

    // 查询库存
    @GetMapping("/query")
    public int queryStock(@RequestParam String productId) {
        return stockService.getStock(productId);
    }
}